package com.hctg.forced2sleep.dialog;

import android.content.Context;
import android.os.Bundle;

import com.actor.myandroidframework.dialog.ViewBindingDialog;
import com.actor.myandroidframework.widget.BaseItemDecoration;
import com.blankj.utilcode.util.SizeUtils;
import com.hctg.forced2sleep.activity.EditMinuteActivity;
import com.hctg.forced2sleep.adapter.SleepTimeSetDialogAdapter;
import com.hctg.forced2sleep.databinding.DialogSleepTimeSetBinding;

/**
 * description: 首页 -> 禅定时长设置
 * company    :
 *
 * @author : ldf
 * date       : 2024/12/1 on 12
 * @version 1.0
 */
public class SleepTimeSetDialog extends ViewBindingDialog<DialogSleepTimeSetBinding> {

    private final OnYesClickListener listener;

    public SleepTimeSetDialog(Context context, OnYesClickListener listener) {
        super(context);
        setWidthPercent(0.888888f, SizeUtils.dp2px(308f));
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final SleepTimeSetDialogAdapter mAdapter = new SleepTimeSetDialogAdapter();

        viewBinding.ivClose.setOnClickListener(v -> dismiss());
        //更多时间
        viewBinding.tvCancel.setOnClickListener(v -> {
            EditMinuteActivity.start(getContext());
        });
        //确定
        viewBinding.tvYes.setOnClickListener(v -> {
            if (listener != null) {
                int minute = mAdapter.getSelectedMinute();
                listener.onYesClick(minute);
            }
            dismiss();
        });

        int dp2 = SizeUtils.dp2px(2f);
        viewBinding.recyclerView.addItemDecoration(new BaseItemDecoration(dp2 * 5, dp2 * 3));
        viewBinding.recyclerView.setAdapter(mAdapter);

        //添加数据
        for (int i = 1; i < 13; i++) {
            mAdapter.addData(i);
        }
    }

    public interface OnYesClickListener {
        void onYesClick(int minute);
    }
}
